/*
 * CSS中用rem作为单位，可适应各屏幕终端
 */
(function(doc, win) {
  var docEl = doc.documentElement,
    resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
    recalc = function() {
      var clientWidth = docEl.clientWidth;
      if (!clientWidth) return;
      window.mtSizeBase = 100 * (clientWidth / 750);
      window.mtSizeBase = window.mtSizeBase > 100 ? 100 : window.mtSizeBase;
      window.mtSizeBase = window.mtSizeBase < 45 ? 45 : window.mtSizeBase;
      docEl.style.fontSize = window.mtSizeBase + 'px';
    };
  if (!doc.addEventListener) return;
  win.addEventListener(resizeEvt, recalc, false);
  doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);

/*
 * 判断浏览器
 */
var browser = {
  versions: function() {
    var u = navigator.userAgent;
    return { //移动终端浏览器版本信息
      weibo: u.toLowerCase().match(/Weibo/i) == "weibo",
      micromessenger: u.toLowerCase().match(/MicroMessenger/i) == "micromessenger", //是否是微信
      mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
      ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
      android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
      iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
      iPad: u.indexOf('iPad') > -1, //是否iPad
      isSAUMSUNG: u.indexOf('SAMSUNG') > -1,
      isMomo: u.indexOf('momoWebView') > -1,
      isApp: u.indexOf('haigou') > -1
    };
  }(),
  language: (navigator.browserLanguage || navigator.language).toLowerCase()
};
